#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "../runtime.h"
#import "visit.h"




void GCVisitChildren(id object, visit_function_t function, void *argument, 
		BOOL visitWeakChildren)
{
    Class class = object->isa;
  
    if(visitWeakChildren==NO) fprintf(stderr,"implement weak ivar layout\n");


    for(;;class=class->super_class){
    struct objc_ivar_list *ivarList=class->ivars;
    int i;

    for(i=0;ivarList!=NULL && i<ivarList->ivar_count;i++){
     char* t=ivarList->ivar_list[i].ivar_type;
     id *ptr=(id*)(((void*)object)+ivarList->ivar_list[i].ivar_offset);
     if(*t=='@' && *ptr) 
     {
		fprintf(stderr,"visit %s %s %x %x\n",ivarList->ivar_list[i].ivar_name,t,(int)ptr,(int)*ptr);
		function(*ptr,argument,visitWeakChildren);
     }

    }

    if(class->isa->isa==(struct objc_class *)class)
     break;
   }

}

